import networkx as nx
import matplotlib.pyplot as plt



# G = nx.Graph()
G = nx.DiGraph()
# G.add_node(1)
# G.add_node(2)
# G.add_nodes_from([1, 2])
G.add_nodes_from([
     (1, {"color": "red"}),
     (2, {"color": "green"})])


# G.add_edge(1,2)
G.add_edges_from([(1, 2, {'weight': 3.1415})])
print(G.number_of_nodes()
,G.number_of_edges())
print(list(G.nodes),
list(G.edges),
G.adj,
list(G.adj[1]), # or list(G.neighbors(1))
G.degree,
G.degree[1], # the number of edges incident to 1
)
subax1 = plt.subplot(121)
nx.draw(G, with_labels=True, font_weight='bold')
plt.show()



import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph() #or G = nx.MultiDiGraph()
G.add_node(0)
G.add_node(1)
G.add_edge(0, 1, length = 2)
G.add_edge(1, 0, length = 3)

pos = nx.spring_layout(G)
# node_labels = nx.get_node_attributes(G, 'desc')
# nx.draw_networkx_labels(G, pos, labels=node_labels)
# edge_labels = nx.get_edge_attributes(G, 'length')
# nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels,label_pos=0.2)

# nx.draw_networkx_edge_labels(G=G,pos=pos,edge_labels=edge_labels,label_pos=0.5,font_size=5)


nx.draw(G, pos, with_labels=True, connectionstyle='arc3, rad = 0.1')
# edge_labels=dict([((u,v,),d['length'])
#              for u,v,d in G.edges(data=True)])

plt.show()